
package com.example.xlzx.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.xlzx.entity.PsychologicalNews;

import com.example.xlzx.result.Result;
import com.example.xlzx.service.IPsychologicalNewsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 心理资讯表 前端控制器
 * </p>
 *
 * @author 1
 * @since 2025-03-07
 */
@RestController
@Tag(name="心理资讯信息")
@RequestMapping("/xlzx/psychologicalNews")
public class PsychologicalNewsController {
    @Autowired
    private IPsychologicalNewsService iPsychologicalNewsService;

    @Operation(summary = "分页查询心理咨询信息")
    @GetMapping("/page")
    public Result<IPage<PsychologicalNews>> pagePsychologicalNews(@RequestParam(required = false) String keyword, @RequestParam int page, @RequestParam int size) {
        Page<PsychologicalNews> pageParam = new Page<>(page, size);
        IPage<PsychologicalNews> psychologicalNewsPageVoPage = iPsychologicalNewsService.pagePsychologicalNews(pageParam, keyword);
        return Result.ok(psychologicalNewsPageVoPage);
    }

    @Operation(summary = "添加心理咨询信息")
    @PostMapping("/add")
    public Result<Boolean> addPsychologicalNews(@RequestBody PsychologicalNews psychologicalNews) {
        return Result.ok(iPsychologicalNewsService.insertPsychologicalNews(psychologicalNews));
    }

    @Operation(summary = "根据id删除心理咨询信息")
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> deletePsychologicalNewsById(@PathVariable Long id) {
        return Result.ok(iPsychologicalNewsService.deletePsychologicalNewsById(id));
    }

    @Operation(summary = "修改心理咨询信息")
    @PutMapping("/update")
    public Result<Boolean> updatePsychologicalNews(@RequestBody PsychologicalNews psychologicalNews) {
        return Result.ok(iPsychologicalNewsService.updatePsychologicalNews(psychologicalNews));
    }

    @Operation(summary = "根据ID查询心理咨询信息")
    @GetMapping("/get/{id}")
    public Result<PsychologicalNews> getPsychologicalNewsById(@PathVariable Long id) {
        return Result.ok(iPsychologicalNewsService.getPsychologicalNewsById(id));
    }
}
